package com.aaa.service.jl.impl;

import com.aaa.dao.jl.ResultSasDao;
import com.aaa.pojo.jl.ResultSas;
import com.aaa.service.jl.ResultSasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.imageio.ImageIO;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class ResultSasServiceImpl implements ResultSasService {
    @Autowired
    private ResultSasDao resultSasDao;
    @Override
    public Map<String, Integer> fidnAll() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<ResultSas> resultSas = resultSasDao.fidnAll();
        Iterator iter = resultSas.iterator();
        while (true){
            while(iter.hasNext()) {
                ResultSas next = (ResultSas) iter.next();
                double forward = next.getForward();
                double inversion = next.getInversion();
                double sum = (forward+inversion)*1.25;
                if (sum<=50.0){
                    ++normal;
                }else if (sum>=50.0 && sum<=59.0){
                    ++mild;
                }else if(sum>= 60.0 && sum<=69.0){
                    ++moderate;

                }else{
                        ++severe;
                    }

            }
            Map<String,Integer> map= new HashMap<>();
            map.put("normal",normal);
            map.put("mild",mild);
            map.put("moderate",moderate);
            map.put("severe",severe);
            return map;
        }

    }

    @Override
    public List<ResultSas> findAll1(String page, String limit) {
        int pageInt = Integer.parseInt(page);
        int limitInt = Integer.parseInt(limit);
        int statr = (pageInt - 1) * limitInt;
        List<ResultSas> all1 = resultSasDao.findAll1(statr,limitInt);
        return all1;
    }

    @Override
    public int findCount() {
        return resultSasDao.findCount();
    }

    @Override
    public ResultSas queryResultSasById(ResultSas resultSas) {
        return resultSasDao.queryResultSasById(resultSas);
    }

    @Override
    public int deleteIdList(List<String> idList) {
        return resultSasDao.deleteIdList(idList);
    }

    @Override
    public List<ResultSas> fuzzyFindAll(String name, String testPlanId,String page, String limit) {
        int pageInt = Integer.parseInt(page);
        int limitInt = Integer.parseInt(limit);
        int statr = (pageInt - 1) * limitInt;

        return resultSasDao.fuzzyFindAll(name,testPlanId,statr,limitInt);

    }

    @Override
    public int countLike(String name, String testPlanId) {
        return resultSasDao.countLike(name, testPlanId);
    }
}
